﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PPIDesktopClient.Entities;
using PPIDesktopClient.Logic;

namespace PPIDesktopClient
{
    public partial class frmDirection : frmDialogBase
    {
        private List<EBaseAsset> m_assets;
        private EBaseAsset m_SelectedAsset;
        private EDistancePositions m_SelectedPositions;
        private List<ECentralOffice> m_Offices;

        public EDistancePositions SelectedPositions
        {
            get
            {
                return m_SelectedPositions;
            }
            set
            {
                m_SelectedPositions = value;
            }
        }

        public void AddAsset(EBaseAsset asset)
        {
            m_assets.Add(asset);
        }
        public EBaseAsset SelectedAsset
        {
            get
            {
                return m_SelectedAsset;
            }
            set
            {
                m_SelectedAsset = value;
            }
        }

        public frmDirection()
        {
            InitializeComponent();
            m_assets = new List<EBaseAsset>();
        }

        private void frmDirection_Load(object sender, EventArgs e)
        {
            ddlAsset.DisplayMember = "Id";
            ddlAsset.DataSource = m_assets;
            m_Offices = LCentralOffice.SelectAll();
            ddlOffice.DataSource = m_Offices;
            ddlOffice.DisplayMember = "Name";

            CheckControlData();
            
        }

        private void CheckControlData()
        {
            if (ddlAsset.Items.Count <= 0)
            {
                rbAssetToCentralOffice.Checked = true;
                rbAssetToAsset.Enabled = false;
                rbAssetToAsset.Checked = false;
                ddlAsset.Enabled = false;
            }
            else
            {
                rbAssetToCentralOffice.Checked = false;
                ddlAsset.Enabled = true;
                rbAssetToAsset.Enabled = true;
                rbAssetToAsset.Checked = true;
            }

            if (ddlOffice.Items.Count <= 0)
            {
                rbAssetToAsset.Checked = true;
                rbAssetToCentralOffice.Checked = false;
                rbAssetToCentralOffice.Enabled = false;
                ddlAsset.Enabled = false;
            }
            else
            {
                rbAssetToAsset.Checked = true;
                rbAssetToCentralOffice.Checked = true;
                rbAssetToCentralOffice.Enabled = true;
                ddlAsset.Enabled = true;

            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            m_assets.Clear();
            this.DialogResult = DialogResult.Cancel;
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            EBasePosition tmpPosition; 
            if (rbAssetToAsset.Checked)
            {
                tmpPosition = (EBasePosition)ddlAsset.SelectedItem;
            }
            else
            {
                tmpPosition = (EBasePosition)ddlOffice.SelectedItem;
            }
            m_SelectedPositions = new EDistancePositions(m_SelectedAsset,tmpPosition);
        }


    }
}
